import multiprocessing
import time
import os
def func1(num):
    # 查看进程id
    print("func1", os.getpid())
    # 查看父进程id
    print("func1p", os.getppid())
    for i in range(num):
        time.sleep(.2)
        print("func1", i)

def func2(num):
    print("func2", os.getpid())
    print("func2p", os.getppid())
    for i in range(num):
        time.sleep(.2)
        print("func2", i)

if __name__ == '__main__':
    # func1()
    # func2()
    print(os.getpid())
    # 设置参数。 守护进程，  守护进程： 当主进程结束的时候守护进程一并消失
    process1 = multiprocessing.Process(target=func1, args=(10,))
    process2 = multiprocessing.Process(target=func2, kwargs={"num":10}, daemon=True)
    # process1.daemon = True
    process1.start()
    process2.start()
    time.sleep(2)
    # 终止进程1
    process1.terminate()
    print("主进程结束")




